<template>
    <view class="fixed-bottom">
        <view class="b-delete b-delete-txt" @click="onDelGoods" v-if="isDel"
            >删除</view
        >
        <view class="b-copy" @click="onCopyGoods" v-if="isEdit">复制</view>
        <view class="b-copyreader" @click="editGoods" v-if="isEdit">编辑</view>
    </view>
</template>

<script>
import config from "../../js/conf/Config.js";
import lang from "../../js/conf/Lang.js";
import eventCtrl from "../../js/event/EventCtrl.js";
import https from "../../js/https/Https.js";
import staticConst from "../../js/const/StaticConst.js";
import localStore from "@/js/LocalStore.js";

export default {
    props: ["goodId", "isEdit", "isDel"],
    data() {
        return {};
    },

    methods: {
        //****** 删除产品 DEL_GOODS ******//
        async onDelGoods() {
            let d = {};
            (d.content = lang.tipTxt.sureDelGdTxt), (d.showCancel = true);
            lang.showWin(d, delGood);
            let that = this;
            async function delGood(data) {
                if (data.confirm) {
                    let param = {};
                    param.gdid = that.goodId;
                    https.delPorjectGoods(param, callBack);
                }
            }

            function callBack(data) {
                if (data && data.status == 1) {
                    that.$msg({ title: lang.tipTxt.delGoodsTxt });
                    uni.$emit(eventCtrl.ACTION_GOODS_EVENT, that.goodId);
                }
            }
        },

        /***编辑产品***/
        async editGoods() {
            this.opstionGoods(staticConst.ACT_GOODS_EIDT);
        },

		/****操作产品****/
		async opstionGoods (actType) {
			let param = {
				id: this.goodId,
			};
			let url = config.YY_CARD_INFO;
			let res = await this.$api({url: url,data: param});
			if (!res.status || !res.data) return false;
			// console.log(res);
			let data = JSON.parse(JSON.stringify(res.data));
			localStore.setCardInfo(data)
			uni.$emit(eventCtrl.EDIT_GOODS_EVENT, data);
		},

        /****操作产品****/
    //     async opstionGoods(actType) {
    //         let that = this;
    //         let param = {};
    //         param.gdid = this.goodId;
    //         https.loadprojectInfo(param, callBack);

    //         function callBack(data) {
    //             console.log(data);
				// data.goodsInfo = data.gd_info
				// data.goodsInfo.imgs_base = data.goodsInfo.imgs
				// data.goodsInfo.prices = data.goodsInfo.price_ls
				// data.goodsInfo.costs = data.goodsInfo.cost_ls
                
    //             let gdTimeTpl = data.gd_info ? data.gd_info.time_tpl : 0; //产品模板时间
    //             let timeTpl = data.tpl_info ? data.tpl_info.time_tpl : 0; //模板最后改动时间
    //             if (gdTimeTpl == timeTpl) {
    //                 data.actType = actType; //编辑
    //                 uni.$emit(eventCtrl.EDIT_GOODS_EVENT, data);
    //             } else {
    //                 //提示模板发生变化，要使用新的模板
    //                 let obj = {};
    //                 obj.content = lang.tlpTxt.title;
    //                 obj.showCancel = true;
    //                 obj.data = data;
    //                 lang.showWin(obj, tlpCallBack);
    //             }
    //         }

    //         function tlpCallBack(res) {
    //             if (res && res.confirm) {
    //                 //确认使用新模板
    //                 res.data.actType = actType; //编辑
    //                 uni.$emit(eventCtrl.EDIT_GOODS_EVENT, res.data);
    //             }
    //         }
    //     },

        /*****复制产品****/
        async onCopyGoods() {
            let d = {};
            (d.content = lang.tipTxt.copyGdTxt), (d.showCancel = true);
            lang.showWin(d, copyGoods);
            let that = this;
            function copyGoods(data) {
                if (data.confirm) {
                    that.opstionGoods(staticConst.ACT_GOODS_COPY);
                }
            }
        },
    },
};
</script>

<style lang="scss">
.fixed-bottom {
    height: 60px;
    right: 0;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #ececec;
    border-bottom: 1px solid #ececec;
    overflow-x: auto;
    z-index: 99;
    font-size: 16px;
    display: flex;
    justify-content: flex-end;
    .b-copyreader {
        cursor: pointer;
        width: 200px;
        height: 60px;
        background: #3388ff;
        color: #fff;
        text-align: center;
        line-height: 60px;
    }

    .b-copyreader:hover {
        opacity: 0.9;
    }
    .b-copyreader:active {
        opacity: 0.8;
    }
    .b-delete,
    .b-copy {
        cursor: pointer;
        width: 100px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        color: #333;
    }

    .b-delete-txt {
        color: #ff0000;
    }

    .b-delete:hover,
    .b-copy:hover {
        background-color: #eee;
    }

    .b-copy:active,
    .b-delete:active {
        background-color: #dedede;
    }
}
</style>
